/*
 * @lc app=leetcode.cn id=1002 lang=javascript
 *
 * [1002] 查找常用字符
 */

// @lc code=start
/**
 * @param {string[]} words
 * @return {string[]}
 */
var commonChars = function (words) {
  const res = [];
  [...new Set(words[0].split(''))]
    .forEach(ch => {
      const num = Math.min(
        ...words.map(
          word => word
            .split('')
            .filter(c => c === ch)
            .length
        )
      );
      res.push(...Array(num).fill(ch));
    });
  return res;
};
// @lc code=end

